//
//  MainTabBarViewContriller.swift
//  sina
//
//  Created by lixuelei on 5/10/15.
//  Copyright © 2015 itcast. All rights reserved.
//

import UIKit

class MainTabBarViewContriller: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!

  
    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewController()
        
        mainTabBar.composeButton.addTarget(self, action: "composeDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }

    func composeDidClick(){
        //打印当前调用的函数
        print(__FUNCTION__)
    }
    
    
    
   //添加子视图控制器
    func addChildViewController() {
//        self.tabBar.tintColor = UIColor.orangeColor()
        addchildViewController("Home", "首页", "tabbar_home")
        addchildViewController("Message", "消息", "tabbar_message_center")
        addchildViewController("Discover", "发现", "tabbar_discover")
        addchildViewController("Profile", "我", "tabbar_profile")

    }
    
    //添加单式图控制器
    func addchildViewController(sbName: String, _ title: String, _ imageName: String){
        let sb = UIStoryboard(name: sbName, bundle: nil)
        
        //as!强制定一个有值的对象
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        //设置title
        nav.topViewController?.title = title
        //添加图片
        nav.tabBarItem.image = UIImage (named: imageName)
        
        addChildViewController(nav)
    
    }

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
